package com.heima.wemedia.controller;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dto.WmNewsDto;
import com.heima.model.wemedia.entity.WmChannel;
import com.heima.wemedia.service.WmChannelService;
import com.heima.wemedia.service.WmNewsService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 自媒体频道表(WmChannel)表控制层
 *
 * @author makejava
 * @since 2022-04-10 21:58:03
 */
@RestController
@RequestMapping(path = "/api/v1/channel")
public class WmChannelController {
    /**
     * 服务对象
     */
    @Resource
    private WmChannelService wmChannelService;

    /**
     * 服务对象
     */
    @Resource
    private WmNewsService wmNewsService;

    /**
     * 分页查询
     *
     * @param wmChannel 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<WmChannel>> queryByPage(WmChannel wmChannel, PageRequest pageRequest) {
        return ResponseEntity.ok(this.wmChannelService.queryByPage(wmChannel, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<WmChannel> queryById(@PathVariable("id") Long id) {
        return ResponseEntity.ok(this.wmChannelService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param wmChannel 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<WmChannel> add(WmChannel wmChannel) {
        return ResponseEntity.ok(this.wmChannelService.insert(wmChannel));
    }

    /**
     * 编辑数据
     *
     * @param wmChannel 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<WmChannel> edit(WmChannel wmChannel) {
        return ResponseEntity.ok(this.wmChannelService.update(wmChannel));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Long id) {
        return ResponseEntity.ok(this.wmChannelService.deleteById(id));
    }

    /**
     * 查询所有频道
     * @return
     */
    @GetMapping(path = "/channels")
    public ResponseResult queryAll(){
        return wmChannelService.queryAll();
    }



}

